package xyz.zhouzhousag.server.service.impl;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import xyz.zhouzhousag.server.dao.NodeTabDao;
import xyz.zhouzhousag.server.pojo.entity.NodeTab;
import xyz.zhouzhousag.server.service.NodeTabService;

import javax.annotation.Resource;

/**
 * 节点板块表(NodeTab)表服务实现类
 *
 * @author Yin.Liu8
 * @since 2021-09-26 16:21:13
 */
@Service("nodeTabService")
public class NodeTabServiceImpl implements NodeTabService {
    @Resource
    private NodeTabDao nodeTabDao;

    /**
     * 通过ID查询单条数据
     *
     * @param nodeTabId 主键
     * @return 实例对象
     */
    @Override
    public NodeTab queryById(Integer nodeTabId) {
        return this.nodeTabDao.queryById(nodeTabId);
    }

    /**
     * 分页查询
     *
     * @param nodeTab     筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<NodeTab> queryByPage(NodeTab nodeTab, PageRequest pageRequest) {
        long total = this.nodeTabDao.count(nodeTab);
        return new PageImpl<>(this.nodeTabDao.queryAllByLimit(nodeTab, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param nodeTab 实例对象
     * @return 实例对象
     */
    @Override
    public NodeTab insert(NodeTab nodeTab) {
        this.nodeTabDao.insert(nodeTab);
        return nodeTab;
    }

    /**
     * 修改数据
     *
     * @param nodeTab 实例对象
     * @return 实例对象
     */
    @Override
    public NodeTab update(NodeTab nodeTab) {
        this.nodeTabDao.update(nodeTab);
        return this.queryById(nodeTab.getNodeTabId());
    }

    /**
     * 通过主键删除数据
     *
     * @param nodeTabId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer nodeTabId) {
        return this.nodeTabDao.deleteById(nodeTabId) > 0;
    }
}
